#pragma once
#include <arpa/inet.h>
#include <cstdint>
#include <iostream>
#include <netinet/in.h>

class InetAddr { // 实现网络地址和本地地址之间的转换
public:
    InetAddr(struct sockaddr_in& addr) : _addr(addr) {
        _ip = inet_ntoa(_addr.sin_addr);
        _port = ntohs(_addr.sin_port);
    }
    uint16_t Port() {
        return _port;
    }
    std::string Ip() {
        return _ip;
    }   
    ~InetAddr() { }
private:
    struct sockaddr_in _addr;
    std::string _ip;
    uint16_t _port;
};